﻿@model IEnumerable<BenzInfo.Hockey.Grenadiers.Models.Staff>
@using BenzInfo.Hockey.Grenadiers.Models

@{
    ViewBag.Title = "Index";
}

<script type="text/javascript">

    $(document).ready(function () {
        if ("@(ViewBag.CurrentUser != null)" == "True")
        {
            $('.staff ul').sortable({
                items: "li:not(:last-child)",
                stop: function (event, ui) {

                    var items = [];
                    $.each($('li:not(:last-child)', this), function (i, elem) {
                        items[i] = $(elem).attr('id').split('_')[1];
                    });

                    $.post('Staff/EditPosition', $.param({ items: items }, true));
                }
            });
        }

        $('.staff ul').disableSelection();

        $('.staff li').hover(function () {
            $('.buttons', this).show();
        }, function () {
            $('.buttons', this).hide();
        });

        $('#dialog_staff').dialog({
            autoOpen: false,
            modal: true,
            draggable: false,
            resizable: false,
            width: 580,
            height: 'auto',
            buttons: [
                {
                    id: 'dialog_btn_save', text: '@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Save',
                    click: function () {
                        $('form', this).submit();
                    }
                }, 
                {
                    id: 'dialog_btn_cancel', text: '@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Cancel',
                    click: function () {
                        $(this).dialog('close');
                    }
                }
            ]
        });

        $('.staff .buttons a').click(function () {
            var url = $(this).attr('href');
            var title = '';

            if (url.indexOf('Create') > 0) {
                title = '@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Create';
                $('#dialog_btn_save span').html(title);
            }
            else if (url.indexOf('Edit') > 0) {
                title = '@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Edit';
                $('#dialog_btn_save span').html('@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Save');
            }
            else if (url.indexOf('Delete') > 0) {
                title = '@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Delete';
                $('#dialog_btn_save span').html(title);
            }

            $('#dialog_staff').empty().load(url, function () {
                $('#dialog_staff').dialog('option', 'title', title).dialog('open');
            });

            return false;
        });
    });

</script>

<h1>@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Staff</h1>

<div id="dialog_staff"></div>

@foreach (Staff.CategoryEnum category in Enum.GetValues(typeof(Staff.CategoryEnum)))
{
    var LabelCategory = @BenzInfo.Hockey.Grenadiers.Resources.Models.Staff.ResourceManager.GetString("CategoryEnum_" + category);

    <div class="staff">
        <h2>@LabelCategory</h2>
        <ul class="sortable">
        @foreach (var item in Model.Where(m => m.Category == category).OrderBy(m => m.Position))
        {
            var picture_url = item.Picture ?? "img_no_picture.jpg";
            <li id="item_@(item.Id)" style="background-image: url(@Url.Content("~/Utils/ImageHandler.ashx?src=staff/" + picture_url + "&width=250"))">
                <span class="buttons">
                    @if (ViewBag.CurrentUser != null)
                    {                    
                        @Html.ActionLink(BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Edit, "Edit", new { id = item.Id })
                        @Html.ActionLink(BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Delete, "Delete", new { id = item.Id })
                    }
                </span>
                <div class="info">
                    <b>@Html.DisplayFor(modelItem => item.FullName)</b><br />
                    @((ViewBag.Lang.IndexOf("fr") >= 0) ? Html.DisplayFor(modelItem => item.TitleFR) : Html.DisplayFor(modelItem => item.TitleEN))
                </div>
            </li>
        }
        @if (ViewBag.CurrentUser != null)
        {
            <li class="item_new" style="background-image: url(@Url.Content("~/Utils/ImageHandler.ashx?src=staff/img_no_picture.jpg&width=250"))">
                <span class="buttons">@Html.ActionLink(BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Create, "Create", new { Category = (int)category })</span>
                <div class="info new">
                    <b>@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.AddPerson</b><br />
                    @LabelCategory
                </div>
            </li>
        }
        </ul>
        <div class="clear"></div>
    </div>
}

